<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>


    <% include ./user_component/head.ejs%>
    <script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="/ueditor/lang/zh-cn/zh-cn.js"> </script>
    <script src="/js/dataHelper.js"></script>
    <style type="text/css">
        div {
            width: 100%;
            position: relative;
            display: block;
        }

        #title {
            height: 30px;
            width: 30%;
            padding: 10px auto;
            margin: 30px auto;
            display: block;
        }
    </style>

<body>
    <div>
        <input id="title" placeholder="请输入文章的标题"></input>
        <script id="editor" type="text/plain" style="width:1024px;height:500px;display: block;margin: 0 auto"></script>
    </div>
    <button id="tijiao" style="display:block;margin:40px auto">保存文章</button>
    <script type="text/javascript">
        var catetory = {};
        //实例化编辑器
        //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
        var ue = UE.getEditor('editor');
        var da = new Date();
        da = da.Format('yyyy/MM/dd hh:mm:ss');
        $('#tijiao').click(function () {
            $.ajax({
                url: '/api/addNotice',
                method: 'POST',
                header: {
                    'content-type': 'application/json' // 默认值
                },
                data: {
                    article: UE.getEditor('editor').getContent(),
                    title: $('#title')[0].value,
                    time: da,
                },
                success: function (e) {
                alert('添加成功')
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            if (parent) {
                                parent.layer.close(index);
                            }
                            parent.history.go(0) 
                      
                },
                fail: function (err) {
                    console.log(err);
                },
                complete: function (e) {

                }
            }
            )
        })
    </script>
</body>

</html>
